package cn.getech.data.development.service;

import cn.getech.data.development.config.properties.OozieConfig;
import cn.getech.data.development.dto.IdAndNameDto;
import cn.getech.data.development.dto.JobLinkDto;
import cn.getech.data.development.dto.JobNodeInfoDto;
import cn.getech.data.development.dto.JobNodeLayConfigDto;
import cn.getech.data.development.entity.JobInfo;
import cn.getech.data.development.entity.JobNodeConfig;
import cn.getech.data.development.entity.JobNodeInfo;
import cn.getech.data.development.model.vo.CopyJobNodeInfoVO;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 任务节点信息表 服务类
 * </p>
 *
 * @author zenith
 * @since 2019-07-08
 */
public interface JobNodeInfoService extends IService<JobNodeInfo> {


    JobNodeInfo getByNodeKeyAndProc(Integer procId, Integer nodeKey);

    /**
     * @Description 验证对应的节点配置信息是否正确
     * @Author hujz
     * @Date 2019/8/9 12:46
     * @Param jobNodeConfig 对应的节点配置信息  任务类型 0 开始 1 数据接入 2 SQL计算 3 程序执行 4 数据推送 5 结束
     * @Return
     * @Exception
     */
    void checkJobConfigInfo(JobNodeConfig jobNodeConfig, Integer typeId) throws Exception;

    /**
     * @Description 验证只有一个开始节点配置、开始节点是否有其它的连线、所有节点是否配置参数。还得设置关联
     * @Author hujz
     * @Date 2019/8/9 18:13
     * @Param 参数数据
     * @Return
     * @Exception
     */
    void checkJobConfigData(JobInfo jobInfo) throws Exception;

    /**
     * @Description 新增或者保存节点数据
     * @Author hujz
     * @Date 2019/8/14 19:40
     * @Param param job的参数数据
     * @Return
     * @Exception
     */
    void saveOrUpdateJobNode(JobNodeInfo param);

    /**
     * @Description 初始化对应的节点和job记录信息
     * @Author hujz
     * @Date 2019/8/16 9:56
     * @Param jobId
     * @Return
     * @Exception
     */
    void initJobHistoryAndJobNodeHistory(JobInfo param, String confParams);


    /**
     * @Description 启用或者禁用需要禁用的node和禁用jenkins中的数据
     * @Author hujz
     * @Date 2019/8/14 16:55
     * @Param needDisabledNodeList:需要进行禁用的nodekey   id:jobId  jobNodeInfos: job节点的信息  flage:true:启用，false:禁用
     * @Return
     * @Exception
     */
    void disabledOrabledJenkins(Set<String> needDisabledNodeList, List<JobNodeInfo> jobNodeInfos, Integer id, Boolean flage);


    /**
     * @Description 获取到当前这个job, 对应的连线关系，并且按照连线关系进行排序
     * @Author hujz
     * @Date 2019/12/26 17:10
     * @Param jobId
     * @Return
     * @Exception
     */
    List<JobNodeInfo> selectJobNodeInfoByJobId(Integer jobId);

    void deleteHdfsInfo(JobNodeInfo jobNodeInfo);

    void deleteHdfsShellFile(JobInfo jobInfo, JobNodeInfo jobNodeInfo);

    /**
     * @param jobNodeInfo
     * @param dst
     * @Description 上传shell文件到hdfs
     */
    void uploadShell(JobNodeInfo jobNodeInfo, String dst, OozieConfig oozieConfig);


    void uploadJobShell(Integer typeId, String dst, OozieConfig oozieConfig,Integer menuDepId);


    void deleteShell(String dst) throws IOException;


    JobNodeConfig checkResourceConfig(JobNodeConfig jobNodeConfig);

    /***
     * 保存节点信息和对应的节点配置
     * @param param
     */
    void saveJobNodeConfig(JobNodeInfo param) throws Exception;

    void saveOrUpdateJobNodeNew(JobNodeInfo param);

    List<JobNodeLayConfigDto> selectJobNodeLayList(JobNodeInfo jobNodeInfo);

    List<JobNodeInfoDto> listAllNodeList(Set<Integer> nodeIds);

    void initJobHistory(List<JobLinkDto> jobLinks, List<JobNodeInfoDto> jobNodeInfos, String confParams, Integer jobId, String oozieJobId, Integer type, Integer jobNodeInfoId, Integer runType, String cronStartTime, String cronEndTime, String cronQueueName);

    void uploadJobLayShell(Integer procId, Integer jobId, String dst, OozieConfig oozieConfig);

    List<JobNodeInfoDto> selectListByIds(Set<Integer> jobNodeIds);

    List<IdAndNameDto> selectNodeLayConfig(Integer jobNodeId);

    void cheackIsDrop(Integer jobNodeId);

    void updateBatch(List<Long> ids, Integer assigneePerId);

    String listRunSysparams(String sql,String jobNodeId);

    String runShellNodes(String jobNodeId);

    JobNodeInfo getDataById(Integer jobNodeId);

    String listRunSysparams(MultipartFile file, String jobNodeId);

    void copySaveJobNodeConfig(CopyJobNodeInfoVO copyJobNodeInfoVO) throws Exception;

    Long concurrentNum(String jobNodeId);

    List<String> filePaths(String jobNodeId);
}
